package com.kcnet.qk.controller.dynamic;

import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import com.kcnet.qk.app.AppContext;
import com.kcnet.qk.constant.Const;
import com.kcnet.qk.constant.StringConst;
import com.kcnet.qk.controller.BasePeopleController;
import com.kcnet.qk.controller.addfriend.AddFriendAdoptCTR;
import com.kcnet.qk.util.FBStringUtil;
import com.kcnet.qk.util.PreferenceHelper;
import com.kcnet.qk.util.RootShell;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import cn.jesse.nativelogger.NLogger;

/**
 * Created by APL on 2018-04-27.
 */

public class TimeLineSendTextCTR extends BasePeopleController {
    private static TimeLineSendTextCTR releaseTextCTR;
    private String Send_Text = "你好啊";
    private static String TAG = "发布文字";

    private boolean isJoinNext;
    /**
     * 获取RongCloud 实例。
     *
     * @return RongCloud。
     */
    public static TimeLineSendTextCTR getInstance() {
        if (releaseTextCTR == null) {
            synchronized (AddFriendAdoptCTR.class) {
                if (releaseTextCTR == null) {
                    releaseTextCTR = new TimeLineSendTextCTR();
                }
            }
        }

        return releaseTextCTR;
    }

    @Override
    public void doTask(AccessibilityEvent event) {
        mClassName = (String) event.getClassName();
        mType = event.getEventType();
        if (!initFbMain && mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals(Const.FbUI.FBLauncherUI)) {
            NLogger.d(TAG, "1.执行发布动态文字 第1/4个功能选项");
            sleepTimedDefault();
            tagTextClick(FBStringUtil.getString(StringConst.TAB_DTXX));
            sleepTimedDefault();
           // tagSendTimeLine();
            RootShell.click(400,393);

            initFbMain = true;
           // execShellCmd("input tap 400 393");
        }  else if (mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals("com.facebook.composer.activity.ComposerActivity")) {
            NLogger.d(TAG,"2点击输入框");
           // Onclic_shell("20","233");
            RootShell.click(20,210);

            NLogger.d(TAG,"3. 发布动态文字输入文本");
            sleepTimedDefault();
            inputSayHiSentence(Send_Text);

            NLogger.d(TAG,"4. 发布动态文字点击分享");
            sleepTimedDefault();
            if(findTextClick(FBStringUtil.getString(StringConst.TIMELINE_XIAYIBU))){
                //如果是下一步
                tagTextClick(FBStringUtil.getString(StringConst.TIMELINE_XIAYIBU));
                isJoinNext = true;
            } else if(findTextClick(FBStringUtil.getString(StringConst.TIMELINE_FENXIANG))){
                tagTextClick(FBStringUtil.getString(StringConst.TIMELINE_FENXIANG));
                stopTask();
            }else if(findTextClick(FBStringUtil.getString(StringConst.TIMELINE_FABU))){
                tagTextClick(FBStringUtil.getString(StringConst.TIMELINE_FABU));
                stopTask();
            }
        }
        else if (isJoinNext && mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals(Const.FbUI.FBIMMERUI)) {
            NLogger.d(TAG,"5. 发布动态文字 选择分享对象");

                if(RootShell.click(487,135)){
                    sleepTimedDefault();
                    RootShell.click(456,885);
                    stopTask();
                }
        }
        else if (mType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && mClassName.equals("X.4N6")) {
            NLogger.d(TAG, "6.点击立即分享");
            //tagTextClick("立即分享");
//            Onclic_shell("18", "888");
            RootShell.click(18,888);
            stopTask();
        }
    }


    public void setParms(String content){
       // stopTask();
        EventBus.getDefault().post(new Boolean(true));
        PreferenceHelper.putBoolean(Const.PREF_KEY_STOP_AUTO_FLAG, true);
        this.Send_Text = content;
        initFbMain = false;
        isJoinNext = false;
    }


}
